#ifndef USTYLEDITEMDELEGATE_H
#define USTYLEDITEMDELEGATE_H

#include <QStyledItemDelegate>

class UStyledItemDelegate : public QStyledItemDelegate
{
    Q_OBJECT
public:
    explicit UStyledItemDelegate(QObject* parent = nullptr);
    ~UStyledItemDelegate();

    void setCheckColumnIndex(int index);

    void setRowHeight(int height);

    int rowHeight();

signals:
    void checkStatusChanged(const QModelIndex &index, bool isChecked);

protected:
    void paint(QPainter* painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;

    QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;

    void initStyleOption(QStyleOptionViewItem* option, const QModelIndex &index) const override;

    void drawChecked(QPainter* painter, const QRect &rect, const QColor &color) const;

    void initCheckBoxStyleOption(QStyleOptionButton* option, const QModelIndex &index) const;

    bool editorEvent(QEvent* event, QAbstractItemModel* model,
                     const QStyleOptionViewItem &option, const QModelIndex &index) override;

    bool handleMouseEvent(QMouseEvent* event, QAbstractItemModel* model,
                          const QStyleOptionViewItem &option, const QModelIndex &index);

private:
    QRect checkBoxRect(const QRect &rect, const QSize &size) const;

    int m_rowHeight = 30;
    int m_width = 18;
    int m_checkColumnIndex = -1;
};

#endif // USTYLEDITEMDELEGATE_H
